package com.zrc.japktool.apk.lib2cppTools.tools;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.List;

public class ProcessHelper {
    public static int processBuilderCommand(List<String> commands, File directory) throws Exception {
        int ret = 0;
        ProcessBuilder pb = new ProcessBuilder(commands);
        if (directory != null) {
            pb.directory(directory);
        }

        Process process = pb.start();
        BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream(), "gbk"));
        String allLine = "";

        for(String line = br.readLine(); line != null; line = br.readLine()) {
            System.out.println(line);
            allLine = allLine + line;
            if (line.indexOf("Built") > 0 && line.indexOf("successfully") > 0 || line.equals("All tasks completed!") || line.equals("请继续......")) {
                ret = 1;
            }
        }

        try {
            process.waitFor();
        } catch (InterruptedException var10) {
            var10.printStackTrace();
        }

        if (ret == 0) {
        }

        try {
            if (process != null) {
                process.destroy();
            }
        } catch (Exception var9) {
        }

        return ret;
    }
}
